//
//  SLTabBarController.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/4.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit
import DCURLRouter
class SLTabBarController: UITabBarController {
    let homePage = SLHomeVC(hiddenTab: false)
    let orderPage = SLRecordVC(hiddenTab: false)
    let minePage = SLMineVC(hiddenTab: false)
    var lastIndex = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        setupVC()
        self.delegate = self
    }
    func setupVC(){
        addChild(homePage, title: "Home", image: "home-default", selectInage: "home-active")
        addChild(orderPage, title: "Record", image: "record-default", selectInage: "record-active")
        addChild(minePage, title: "Me", image: "me-default", selectInage: "me-active")
        
        let blankView = create_view(bgColor: .white, supView: nil) { (make) in}
        blankView.frame = CGRect(x: 0, y: -0.5, width: DevConfig.width, height: DevConfig.tab_height+0.5)
        self.tabBar.addSubview(blankView)
        self.tabBar.backgroundColor = UIColor.white
        self.tabBar.barTintColor = UIColor.white
    }
    func addChild(_ childController: UIViewController,title:String,image:String,selectInage:String) {
        childController.tabBarItem.title = title
        childController.tabBarItem.image = IMAGE(image)
        childController.tabBarItem.selectedImage = IMAGE(selectInage)
        let nav = SLNavigationController(rootViewController: childController)
        nav.isNavigationBarHidden = true
        addChild(nav)
    }
}
extension SLTabBarController:UITabBarControllerDelegate{
    func tabBarController(_ tabBarController: UITabBarController,
                          shouldSelect viewController: UIViewController) -> Bool {
        if viewController.tabBarItem.title == "Record"{
            if !SLUserAccount.isLogin{
                GoToLoginVC()
                return false
            }
        }
    return true
        
    }
}
